package com.tianqi.familymap.adapter

import android.content.Context
import android.graphics.Color
import android.view.View
import android.widget.ImageView
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.tianqi.familymap.R
import com.tianqi.familymap.model.RecommendMultipleModel
import com.tianqi.familymap.utils.ContantUtils


class RecommendMultiAdapter(val mlist: ArrayList<RecommendMultipleModel>, private val ctx: Context) :
    BaseMultiItemQuickAdapter<RecommendMultipleModel, BaseViewHolder>(),LoadMoreModule {
    init {
        addItemType(RecommendMultipleModel.STORY, R.layout.item_story)
        addItemType(RecommendMultipleModel.ALBUM, R.layout.item_album)
    }

    override fun convert(holder: BaseViewHolder, item: RecommendMultipleModel) {
        when(holder.itemViewType){
            RecommendMultipleModel.ALBUM -> {
                holder.setText(R.id.home_music_name, item.nickname)
                Glide.with(ctx).load(ContantUtils.BASE_URL + item.imgs)
                    .into(holder.getView(R.id.home_bg) as ImageView)
                Glide.with(ctx).load(item.avatar)
                    .into(holder.getView(R.id.home_head) as ImageView)
            }
            RecommendMultipleModel.STORY -> {
                val models: MutableList<String> = item.bj_img
                val gridLayoutManager = GridLayoutManager(ctx, 3)
                val imageSingleAdapter = ImageSingleAdapter(models, ctx)
                val imgviews = holder.getView(R.id.recycler_imgs) as RecyclerView
                imgviews.layoutManager = gridLayoutManager
                imgviews.adapter = imageSingleAdapter
                holder.setText(R.id.home_music_name, item.nickname)
                    .setText(R.id.tv_year_box, item.create_time1)
                    .setText(R.id.tv_content, item.body)
                    .setText(
                        R.id.tv_time_box,
                        item.create_time3 + "/" + item.create_time2
                    )
                Glide.with(ctx).load(ContantUtils.BASE_URL + item.thumb)
                    .into(holder.getView(R.id.iv_bj_all) as ImageView)
                Glide.with(ctx).load(item.avatar)
                    .into(holder.getView(R.id.home_head) as ImageView)
                if (item.color_type === 0) {
                    holder.setTextColor(R.id.tv_year_box, -0x1000000)
                        .setTextColor(R.id.tv_content, -0x1000000)
                        .setTextColor(R.id.tv_time_box, -0x1000000)
                    val test: View = holder.getView(R.id.view_line) as View
                    test.setBackgroundColor(Color.parseColor("#000000"))
                }
            }
        }
    }
}